#include <iostream>
#include <cstring>
using namespace std;
#define maxn 101
int N, M;
char map[maxn][maxn];
short vis[maxn][maxn];
int dx[8] = {0, 0, -1, 1, 1, -1, -1, 1};
int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int cnt = 0;
void dfs(int x, int y)
{
    if (map[x][y] != 'W' || vis[x][y] == 1)
        return;
    else
        vis[x][y] = 1;
    for (int i = 0, tx, ty; i < 8; i++)
    {
        tx = x + dx[i], ty = y + dy[i];
        dfs(tx, ty);
    }
}
int main()
{
    cin >> N >> M;
    for (int i = 0; i < N; ++i)
        cin >> map[i];
    for (int x = 0; x < N; ++x)
    {
        for (int y = 0; y < M; ++y)
        {
            if (map[x][y] == 'W' && vis[x][y] == 0)
            {
                cnt++;
                dfs(x, y);
            }
        }
    }
    cout << cnt << endl;
    return 0;
}